clear all
set memo 100m
capture log close

local filename IVResult

log using IVResult, replace text

local output_dir draft
local output_tex1 `filename'.tex


cd "C:\Users\rujia\Dropbox\\Replication\treatyports"

use data/subgroup.dta, clear

gen ln_popu1776=log(hpopu1776)
gen ln_popu1820=log(hpopu1820)

gen preGrowth=(hpopu1820-hpopu1776)/hpopu1776/44*100
gen postGrowth1=( hpopu1953-hpopu1910)/hpopu1910/43*100
gen postGrowth2=( hpopu1964-hpopu1953)/hpopu1953/11*100
gen postGrowth3= (hpopu1982-hpopu1964)/hpopu1964/18*100
gen postGrowth4= (hpopu1990-hpopu1982)/hpopu1982/8*100
gen postGrowth5= (hpopu2000-hpopu1990)/hpopu1990/10*100

gen postGrowth_mean2= (postGrowth1+ postGrowth2+ postGrowth3+ postGrowth4 + postGrowth5)/5

sum postGrowth_mean2
local controls "silk tea dis_yunhe longitude latitude landtax taiping"


#delimit ;
eststo clear;

eststo: regress treatyports nativecustoms;
estadd scalar nobs=e(N);
estadd scalar rsqaure=e(r2);

eststo: regress treatyports nativecustoms `controls';
estadd local controls "Y";
estadd scalar nobs=e(N);
estadd scalar rsqaure=e(r2);


eststo: regress postGrowth_mean2 nativecustoms `controls';
estadd local controls "Y";
estadd scalar nobs=e(N);
estadd scalar rsqaure=e(r2);

eststo: ivreg postGrowth_mean2 `controls' (treatyports=nativecustoms);
estadd local controls "Y";
estadd scalar nobs=e(N);
estadd scalar rsqaure=e(r2);


esttab using draft/`output_tex1', replace
	width(\hsize) 
	mlabel (, depvar)
	b(3)
	se(3)
	noconstant
	star(* 0.10 ** 0.05 *** 0.01)
	keep(
nativecustoms
treatyports
		)
		
	label
	stats(
		
		controls
		 nobs
		 rsquare
		, 
		labels(
	
			"Controls" 
			"\# observations"
			"R-squared"
			) 
		fmt(0)
		layout(@)
		)
	nonotes
	;
